﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace JeanFish.Data.Common
{
    public abstract class DbProviderFactory : System.Data.Common.DbProviderFactory,IServiceProvider
    {
        private System.Data.Common.DbProviderServices services;
        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(System.Data.Common.DbProviderServices))
            {
                return this.services;
            }
            return null;
        }
        protected DbProviderFactory(System.Data.Common.DbProviderServices services)
        {
            this.services = services;
        }

        public override bool CanCreateDataSourceEnumerator
        {
            get
            {
                return base.CanCreateDataSourceEnumerator;
            }
        }

        public static void RegisterProvider(string name, string invariantName, Type factoryType)
        {
            var data = (System.Data.DataSet)ConfigurationManager.GetSection("system.data");
            var providerFactories = data.Tables["DbProviderFactories"];
            providerFactories.Rows.Add(name, name, invariantName, factoryType.AssemblyQualifiedName);
        }
    }
}
